<template>
  <div class="header">
    <h1>我是Header</h1>
    <p>Count的值是{{ count }}</p>
    <p>价格是{{ price }}</p>
    <button @click="increment">累加count的值</button>
    <button @click="incrementN({ n: 3 })">count的值每次加n</button>
    <button @click="incrementWait">等一等再加</button>
  </div>
</template>

<script>
import { mapState } from 'vuex';

export default {
  name: "Header",
  computed:{
    ...mapState(['count','price'])
  },
  methods:{
    increment(){
      this.$store.commit('increment')
    },
    incrementN({n}){
      this.$store.commit('incrementN',{n})
    },
    incrementWait(){
      this.$store.dispatch('incrementWait')
    }
  }
};
</script>

<style scoped>
.header {
  margin: 30px;
  background: yellowgreen;
}
</style>